﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;


namespace IHISCETeim.DAL
{
    public class FTradeInvoiceDAL
    {
       
        public static int Add( FTradeInvoiceInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_Add", obj.FTradeID, obj.FPType, obj.FPDate, obj.FPDaiMa, obj.FPHaoMa, obj.FPJinE, obj.FPRemark, obj.RealName, obj.FPAcceptName);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(int id)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_Delete", id);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetAllByFTradeId(int FTradeId)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_GetAllByFTradeId", FTradeId);
            return DB.ExecuteReader(dbCommand);
        }

        public static IDataReader GetById(int Id)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_GetById", Id);
            return DB.ExecuteReader(dbCommand);
        }
        public static bool Update(FTradeInvoiceInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_Update", obj.id, obj.FPType, obj.FPDate, obj.FPDaiMa, obj.FPHaoMa, obj.FPJinE, obj.FPRemark,obj.FPAcceptName);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
        /// <summary>
        /// 转移发票
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newFtradeId"></param>
        /// <returns></returns>
        public static bool ReUse(int id,int newFtradeId)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeInvoice_ReUse", id, newFtradeId);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
